﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using BeeCoders.Tools.ControlCanvas.Infrastructure;

namespace BeeCoders.Tools.ControlCanvas.DemoApp
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow 
	{
		public MainWindow()
		{
			InitializeComponent();
			Loaded += MainWindowLoaded;
		}

		void MainWindowLoaded(object sender, RoutedEventArgs e)
		{
			//ParameterViewModel = new ParameterViewModel();
			//ParameterViewModel.ControlsToBind = new ObservableCollection<ControlViewModel>();
			//var labelControl = new ControlViewModel();
			//labelControl.Name = "Label";
			//labelControl.ParameterValue = "Name:";
			//labelControl.Prompt = "Label";
			//labelControl.ControlType = ControlTypeEnum.Label;

			//labelControl.Width = 50;
			//labelControl.Height = 25;
			//labelControl.LeftPosition = 50;
			//labelControl.TopPosition = 50;

			//labelControl.IsInDesign = true;
			//MainCanvas.Controls.Add(labelControl);

			//var newControl = new ControlViewModel();
			//newControl.Name = "Test";
			//newControl.ParameterValue = "Test";
			//newControl.ControlType = ControlTypeEnum.TextBox;

			//newControl.LinkedControl = labelControl;

			//newControl.Width = 50;
			//newControl.Height = 25;
			//newControl.LeftPosition = 250;
			//newControl.TopPosition = 50;

			//newControl.IsInDesign = MainCanvas.IsInDesignMode;
			//MainCanvas.Controls.Add(newControl);




			MainCanvas.IsInDesignMode = true;
			MainCanvas.ShowGridLines = false;

			//MainCanvas.DataContext = controls;
		}

		private void RemoveSelectedClick(object sender, RoutedEventArgs e)
		{
			var controlsToDelete = MainCanvas.SelectedControls.ToList();

			foreach (var control in controlsToDelete)
			{
				MainCanvas.Controls.Remove(control);

			}
		}

		private void AddLabelClick(object sender, RoutedEventArgs e)
		{
			var newControl = new ControlViewModel();
			newControl.Name = "Label";
			newControl.Prompt = "Name:";
			newControl.ParameterValue = "Bart";
			newControl.ControlType = ControlTypeEnum.Label;

			newControl.Width = 50;
			newControl.Height = 25;
			newControl.LeftPosition = 50;
			newControl.TopPosition = 100;

			newControl.IsInDesign = MainCanvas.IsInDesignMode;

			MainCanvas.Controls.Add(newControl);

		}



		private void AddTextBoxClick(object sender, RoutedEventArgs e)
		{
			var newControl = new ControlViewModel();
			newControl.Name = "TextBox";
			newControl.Prompt = "John Doe";
			newControl.ParameterValue = "John Doe";
			newControl.ControlType = ControlTypeEnum.TextBox;

			newControl.Width = 50;
			newControl.Height = 25;
			newControl.LeftPosition = 50;
			newControl.TopPosition = 100;

			newControl.TabOrder = 1;

			newControl.IsInDesign = MainCanvas.IsInDesignMode;

			MainCanvas.Controls.Add(newControl);

		}

		private void AddLinkedTextboxClick(object sender, RoutedEventArgs e)
		{
			var newControl = new ControlViewModel();
			newControl.Name = "Label";
			newControl.Prompt = "Name:";
			newControl.ParameterValue = "";
			newControl.ControlType = ControlTypeEnum.Label;

			newControl.Width = 50;
			newControl.Height = 25;
			newControl.LeftPosition = 50;
			newControl.TopPosition = 100;

			newControl.IsInDesign = MainCanvas.IsInDesignMode;

			MainCanvas.Controls.Add(newControl);

			var newControl2 = new ControlViewModel();
			newControl2.Name = "TextBox";
			newControl2.Prompt = "John Doe";
			newControl2.ParameterValue = "John Doe";
			newControl2.ControlType = ControlTypeEnum.TextBox;

			newControl2.Width = 50;
			newControl2.Height = 25;
			newControl2.LeftPosition = 250;
			newControl2.TopPosition = 100;

			newControl2.LinkedControl = newControl;			// links the 2 controls
	
			newControl2.IsInDesign = MainCanvas.IsInDesignMode;

			MainCanvas.Controls.Add(newControl2);
		}

		private void AddNumericTextBoxClick(object sender, RoutedEventArgs e)
		{
			var newControl = new ControlViewModel();
			newControl.Name = "TextBox";
			newControl.Prompt = "John Doe";
			newControl.ParameterValue = "1234";
			newControl.ControlType = ControlTypeEnum.NumericTextBox;

			newControl.Width = 50;
			newControl.Height = 25;
			newControl.LeftPosition = 50;
			newControl.TopPosition = 100;

			newControl.IsInDesign = MainCanvas.IsInDesignMode;

			MainCanvas.Controls.Add(newControl);

		}
		private void AddDropDownClick(object sender, RoutedEventArgs e)
		{
			var newControl = new ControlViewModel();
			newControl.Name = "TextBox";
			newControl.Prompt = "John Doe";
			newControl.ParameterValue = "John Doe";
			newControl.ControlType = ControlTypeEnum.DropDown;

			newControl.Width = 50;
			newControl.Height = 25;
			newControl.LeftPosition = 50;
			newControl.TopPosition = 100;

			newControl.IsInDesign = MainCanvas.IsInDesignMode;

			newControl.ValidValues = new ObservableCollection<ValueViewModel>();
			newControl.ValidValues.Add(new ValueViewModel("Orange", 1));
			newControl.ValidValues.Add(new ValueViewModel("Apple", 2));
			newControl.ValidValues.Add(new ValueViewModel("Grape", 1));


			MainCanvas.Controls.Add(newControl);

		}

		private void AddCheckBoxClick(object sender, RoutedEventArgs e)
		{
			var newControl = new ControlViewModel();
			newControl.Name = "TextBox";
			newControl.Prompt = "John Doe";
			newControl.ParameterValue = true;
			newControl.ControlType = ControlTypeEnum.CheckBox;

			newControl.Width = 150;
			newControl.Height = 25;
			newControl.LeftPosition = 50;
			newControl.TopPosition = 100;

			newControl.IsInDesign = true;

			MainCanvas.Controls.Add(newControl);
		}

		private void AddDateTimeClick(object sender, RoutedEventArgs e)
		{
			var newControl = new ControlViewModel();
			newControl.Name = "TextBox";
			newControl.Prompt = "John Doe";
			newControl.ParameterValue = DateTime.Now;
			newControl.ControlType = ControlTypeEnum.DateTimePicker;

			newControl.Width = 150;
			newControl.Height = 25;
			newControl.LeftPosition = 50;
			newControl.TopPosition = 100;

			newControl.IsInDesign = true;

			MainCanvas.Controls.Add(newControl);
		}

		private void AddCalendarClick(object sender, RoutedEventArgs e)
		{
			var newControl = new ControlViewModel();
			newControl.Name = "Calendar";
			newControl.Prompt = "Birthdate";
			newControl.ParameterValue = DateTime.Now;
			newControl.ControlType = ControlTypeEnum.Calendar;

			//newControl.Width = 150;
			//newControl.Height = 150;
			newControl.LeftPosition = 150;
			newControl.TopPosition = 100;

			newControl.IsInDesign = true;

			MainCanvas.Controls.Add(newControl);
		}

		private void AlignLeftClick(object sender, RoutedEventArgs e)
		{
			MainCanvas.AlignLeft();
		}

		private void AlignRightClick(object sender, RoutedEventArgs e)
		{
			MainCanvas.AlignRight();
		}

		private void AlignTopClick(object sender, RoutedEventArgs e)
		{
			MainCanvas.AlignTop();
		}

		private void AlignBottomClick(object sender, RoutedEventArgs e)
		{
			MainCanvas.AlignBottom();
		}

		private void AlignHorMiddlesClick(object sender, RoutedEventArgs e)
		{
			MainCanvas.AlignHorMiddles();
		}

		private void AlignVerMiddlesClick(object sender, RoutedEventArgs e)
		{
			MainCanvas.AlignVerMiddles();

		}

		private void SaveToXmlClick(object sender, RoutedEventArgs e)
		{
			MainCanvas.SaveToXml(@"d:\test.xml");
		}

		private void LoadFromXmlClick(object sender, RoutedEventArgs e)
		{
			MainCanvas.LoadFromXml(@"d:\test.xml");

		}





	}
}
